﻿using System;
using OpenLS.Spreadsheet.Expressions;

namespace OpenLS.Spreadsheet
{
    public class CellValueChangedEventArgs<T>: ValueChangedEventArgs<T>

    {

        internal  CellValueChangedEventArgs(Cell cell, T oldValue, T newValue): base(cell, oldValue, newValue)
        {
        }

    }
    public class CellFormulaChangedEventArgs: CellEventArgs
    {
        private readonly Expression _oldExpression;
        private readonly Expression _newExpression;

        internal CellFormulaChangedEventArgs(Cell cell, Expression oldExpression, Expression newExpression)
            : base(cell)
        {
            _oldExpression = oldExpression;
            _newExpression = newExpression;
        }
        public string OldFormula
        {
            get
            {
                if (_oldExpression == null)
                    return null;
                return _oldExpression.GetTextWithEqual(new TextContext(new CellEvaluationContext(base.Cell)));
            }
        }
        public string NewFormula
        {
            get
            {
                if (_newExpression == null)
                    return null;
                return  _newExpression.GetTextWithEqual(new TextContext(new CellEvaluationContext(base.Cell)));
            }
        }
    }
    [Obsolete ("Use CellValuechangedEventArgs instead")]
    public class ValueChangedEventArgs<T>: CellEventArgs
    {
        private readonly T _oldValue;
        private readonly T _newValue;

        protected ValueChangedEventArgs(Cell cell, T oldValue, T newValue): base(cell)
        {
            _oldValue = oldValue;
            _newValue = newValue;
        }

        public T NewValue
        {
            get { return _newValue; }
        }

        public T OldValue
        {
            get { return _oldValue; }
        }
    }
}